/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-06 17:36:29
 * @LastEditors: 赵大壮
 */
import { Component, Vue, Inject } from "vue-property-decorator";
import DZServiceStaff from "../service/DZServiceStaff";
import UiDialogAddStaff from "@/components/ui-dialog/UiDialogAddStaff.vue"
import UiDialogEditStaff from "@/components/ui-dialog/UiDialogEditStaff.vue"
import UiDialogImportStaff from "@/components/ui-dialog/UiDialogImportStaff.vue"
import dzMsgBox from "@/utils/DZMessageBox";
import DZModelStaff from "@/views/员工管理/model/DZModelStaff";
import nyNetwork from "@/api/nyBaseNetwork";

@Component({
    components: { UiDialogAddStaff, UiDialogImportStaff ,UiDialogEditStaff}
})
export default class Index extends Vue {

    s_staff = new DZServiceStaff();

    m_staff = new DZModelStaff();

    dialog_add_staff = false;

    dialog_edit_staff = false;

    dialog_import_staff = false;

    created() { }

    mounted() {
        this.s_staff.company = this.$route.query.id as string;
        this.s_staff.companyName = this.$route.query.name as string;
        this.action_list_data();
    }

    action_page_back() {
        this.$router.push({ path: (this.$route.query.father as string) })
    }

    action_list_data() {
        this.s_staff.net_list_staff();
    }

    beforeDestroy() {

    }
    action_page_change(cur_page) {
        this.s_staff.m_page.page = cur_page;
        this.action_list_data();
    }
    action_reset_pwd(item) {
        dzMsgBox.normal("是否重置该员工的登陆密码？", "重置", () => {
            this.s_staff.net_reset_pwe(item.id)
        })
    }
    action_del(item) {
        dzMsgBox.del("是否删除员工<" + item.name + ">", () => {
            this.s_staff.net_del_staff(item.id, this.action_list_data)
        })

    }
    action_add_staff(data) {
        this.dialog_add_staff = false;
        this.s_staff.net_add_staff(data, this.action_list_data)
    }
    action_edit_staff(data) {
        this.dialog_edit_staff = true;
        this.m_staff = Object.assign({},data)
    }
    action_update_staff(data){
        this.s_staff.net_edit_staff(data, this.action_list_data)
    }
    action_staff_bin(){
        this.$router.push({
            path: "/company/staffBin",
            query: { id: this.s_staff.company, name: this.s_staff.companyName, father: this.$route.path }
        })
    }
    //单个冻结
    action_froze(row){
        let id = []
        id.push(row.id)
        this.s_staff.net_froze_staff(id, this.action_list_data)
    }
    //单个解冻
    action_Unfroze(row){
        let id = []
        id.push(row.id)
        this.s_staff.net_Unfroze_staff(id, this.action_list_data)
    }
    //批量冻结
    action_froze_batch(){
        // @ts-ignore
        let selection = this.$refs.staffTable.selection
        let idList = []
        selection.forEach((s) =>{
            idList.push(s.id)
        })
        if(idList.length == 0){
            return
        }else{
            this.s_staff.net_froze_staff(idList, this.action_list_data)
        }
    }

    //批量解冻
    action_unfroze_batch(){
        // @ts-ignore
        let selection = this.$refs.staffTable.selection
        let idList = []
        selection.forEach((s) =>{
            idList.push(s.id)
        })
        if(idList.length == 0){
            return
        }else{
            this.s_staff.net_Unfroze_staff(idList, this.action_list_data)
        }
    }

    //导出
    action_export_data(){
        this.s_staff.net_export_staff();
    }
}